//
//  LeftViewController.m
//  LINNER
//
//  Created by Kendama on 2017/10/10.
//  Copyright © 2017年 weiwang. All rights reserved.
//

#import "LeftViewController.h"
#import "MonitorViewController.h"
#import "WebViewController.h"
#import "HtmlViewController.h"
#import "UserManualViewController.h"
#import "UIViewController+LGSideMenuController.h"
#import "AboutWeViewController.h"
#import "HelpCenterViewController.h"

@interface LeftViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UIImageView *headImageView;
@property (strong, nonatomic) UITableView *tableView;
/** nsarray **/
@property(nonatomic,strong) NSArray *titleArray;

@end

@implementation LeftViewController

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [self setNavigationStyle];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self masLayoutSubview];
}

- (void)setNavigationStyle{
    
    [self setLeftButtonImage:[UIImage imageNamed:@"tittle_back_nor"]];
    [self.navigationController.navigationBar makeTransparent];
}

#pragma mark - --------------------------UITableView dataSource--------------------------

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.textColor = [UIColor colorWithHexString:@"#56504f"];
        [cell.textLabel setFont:[UIFont systemFontOfSize:15.f]];
    }
    cell.textLabel.text = MyNSLocalizedString(self.titleArray[indexPath.row]);
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 56;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return CGFLOAT_MIN;
    
}
#pragma mark - --------------------------UITableView delegate--------------------------

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        [self.sideMenuController hideLeftViewAnimated:YES completionHandler:nil];
    }else if (indexPath.row == 1) {
        
        MonitorViewController *VC = [[MonitorViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
        
    }else if (indexPath.row == 2){
        
        WebViewController *vc = [WebViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 3){
        HelpCenterViewController *vc = [[HelpCenterViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
//        HtmlViewController *vc = [HtmlViewController new];
//        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 4){
        AboutWeViewController *vc = [[AboutWeViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
//        [SVProgressHUD showInfoWithStatus:MyNSLocalizedString(@"Version 1.1")];
    }
    
    
}

- (NSArray *)titleArray{
    
    if (!_titleArray) {
        
        _titleArray = @[MyNSLocalizedString(@"选择产品"),MyNSLocalizedString(@"噪声检测"),MyNSLocalizedString(@"Linner官网"),MyNSLocalizedString(@"帮助中心"),MyNSLocalizedString(@"关于")];
        
    }
    return _titleArray;
}

- (UIImageView *)headImageView
{
    if(!_headImageView)
    {
        UIView *superView = self.view;
        _headImageView = [[UIImageView alloc]init];
        [superView addSubview:_headImageView];
        _headImageView.image = [UIImage imageNamed:@"bg_92"];
    }
    return _headImageView;
}

- (UITableView *)tableView
{
    if(!_tableView)
    {
        UIView *superView = self.view;
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
        [superView addSubview:_tableView];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.view;
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top);
        make.left.mas_equalTo(superView.mas_left);
        make.width.mas_equalTo(px1080Width(720));
        make.height.mas_equalTo(px1920Height(522));
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headImageView.mas_bottom);
        make.left.mas_equalTo(superView.mas_left);
        make.width.mas_equalTo(px1080Width(720));
        make.bottom.mas_equalTo(superView.mas_bottom);
    }];
}

@end
